//-------------------------------------------------------------------
//	Copyright (c) 2010-2012 Zhirnov Andrey
//	This file is part of the "UXGEN" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#ifndef _UX_THREAD_MANAGER_H
#define _UX_THREAD_MANAGER_H

#include "../Core/CCore.h"
#include "IThread.h"

namespace Engine
{
namespace CoreSystems
{

	//
	// Thread Manager
	//

	class _EXPORT_ CThreadManager : public CEngBaseObject
	{
	private:
		CCore		*		_pCore;
		thread_array_t		_aThreads;
		TReadWriteSync		_sLockThreads;
		
	private:
		void _AddThread(IThread *pThread);

		// CEngBaseObject //
		virtual void Release();

	public:
		CThreadManager(CCore *pCore);
		~CThreadManager();

		bool PushOp(e_thread::type eType, IOperation *pOp, bool bHightPriority = false, bool bExceptCurrent = true);
		bool PushOpToAll(e_thread::type eType, IOperationC *pOp, bool bHightPriority = false, bool bExceptCurrent = true);

		bool Start(IThread *pThread, e_thread_priority::type ePriority = e_thread_priority::NORMAL);
		void RemoveThread(IThread *pThread);
		void DestroyAll();
		bool PauseAll();
		bool ResumeAll();

		uint GetCount();
		bool IsCurProcessThread();
	};

//-------------------------------------------------------------------

}	// CoreSystems
}	// Engine

#endif	// _UX_THREAD_MANAGER_H